package com.geor.gcv.ict.train;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.opencv.core.Mat;

import com.geor.gcv.core.process.ThresholdProcess;
import com.geor.gcv.core.process.GrayProcess;
import com.geor.gcv.core.process.InputProcess;
import com.geor.gcv.core.process.ResizeProcessAny;

public class TrainerSVMModule extends TrainerAbstract {
	Ml ml = new MlSVM();

	static {
		WIDTH = 60;
		HEIGHT = 60;
		TOTAL = WIDTH * HEIGHT;
	}

	public TrainerSVMModule() {
		dealBool = true;
	}

	@Override
	public void train(Mat trainData, Mat label, String out) {
		log.info("training ....");
		ml.train(trainData, label, out);
		log.info("over :" + out);
	}

	@Override
	public Map<String, List<Mat>> deal(Map<String, List<Mat>> maps) {
		Map<String, List<Mat>> temps = new HashMap<String, List<Mat>>();
		for (String str : maps.keySet()) {
			List<Mat> lists = new ArrayList<Mat>();
			List<Mat> mats = maps.get(str);
			for (int i = 0; i < mats.size(); i++) {
				Mat mat = mats.get(i);
				ResizeProcessAny process = new ResizeProcessAny(
						new ThresholdProcess(new GrayProcess(new InputProcess(mat)), 21, 30), WIDTH, HEIGHT);
				mat = process.process();
				lists.add(mat);
			}
			temps.put(str, lists);
		}
		maps.clear();
		return temps;
	}

}